/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.academy.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ar.uba.fi.posgrado.common.model.AbstractDomainObject;

/**
 * Materia
 * 
 * @author ariel.piechotka
 * 
 */

@Entity
@Table(name = "MATERIA")
@SuppressWarnings("serial")
public class Subject extends AbstractDomainObject implements
		Comparable<Subject> {

	@Column(name = "CODIGO", length = 10)
	private String code;

	@Column(name = "NOMBRE", length = 45, nullable = false)
	private String name;

	@Column(name = "CREDITOS")
	private short credits;

	@Column(name = "FECHA_ALTA", nullable = false)
	private Date validFrom;

	@Column(name = "FECHA_BAJA")
	private Date validTo;

	@Column(name = "CURRICULA", nullable = false)
	private String curriculum;

	@ManyToMany(mappedBy = "subjects", fetch = FetchType.LAZY)
	private Set<Course> courses;

	@OneToMany(mappedBy = "subject", fetch = FetchType.LAZY)
	private Set<AcademicRecord> academicRecords;

	@Override
	public String[] getExcludedFields() {
		return new String[] { "credits", "validFrom", "validTo",
				"academicRecords", "courses", "curriculum" };
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public short getCredits() {
		return credits;
	}

	public void setCredits(short credits) {
		this.credits = credits;
	}

	public String getCurriculum() {
		return curriculum;
	}

	public void setCurriculum(String curriculum) {
		this.curriculum = curriculum;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getValidFrom() {
		return validFrom;
	}

	public void setValidFrom(Date validFrom) {
		this.validFrom = validFrom;
	}

	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}

	public Set<Course> getCourses() {
		return courses;
	}

	public void setCourses(Set<Course> courses) {
		this.courses = courses;
	}

	public Set<AcademicRecord> getAcademicRecords() {
		return academicRecords;
	}

	public void setAcademicRecords(Set<AcademicRecord> academicRecords) {
		this.academicRecords = academicRecords;
	}

	public int compareTo(Subject o) {
		return code.compareTo(o.code);
	}
}
